#include "shm.hpp"
#include "namedpipe.hpp"
using namespace std;
// client 是写端

int main()
{
    //引入管道之后就可以让写端写完之后，读端才开始读了  
    Shm shm(gpathname, gproj_id, gUser);
    shm.zero();
    char* shmaddr = (char*)shm.addr();
    sleep(3);

    std::string info = {'i',' ', 'a', 'm', ' ', 'p', 'r', 'o', 'c', 'e', 's', 's', ' ', 'A'};
    NamedPipe fifo(common_path, User);
    fifo.openForWrite();
    int i = 0;
    for(auto ch : info)
    {
        shmaddr[i++] = ch;
    }
    
    std::string tmp = "I am client";
    // std::cout << "I am writing information..." << std::endl;
    fifo.writeNamedPipe(tmp);
    sleep(5);
    // char ch = 'A';
    // while (ch <= 'Z')
    // {
    //     shmaddr[ch-'A'] = ch;
    //     std::string tmp = "wakeup";
    //     std::cout << "add " << ch << " into Shm, " << "wakeup reader" << std::endl;
    //     fifo.writeNamedPipe(tmp);
    //     sleep(2);
    //     ch++;
    // }

    char *addr = (char *)shm.attachShm();
    return 0;
}
